
package com.qingzhuge.member.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.qingzhuge.entity.BaseBean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

/**
 * @author : zero.xiao
 * @description : 头像URL
 * @date :2018/9/25 0025 下午 17:07
 * @since : 1.0.0
 * @modified :
 */
@Getter
@Setter
@Entity
@Table(name = "sys_member_avatar")
public class SysMemberAvatar extends BaseBean<Long> {
    private static final long serialVersionUID = -9032628727048882233L;
    @Id
    @GeneratedValue(generator = "idLongGenerate")
    @GenericGenerator(name = "idLongGenerate", strategy = "com.qingzhuge.dao.id.IdLongGenerate")
    private Long id;
    @ApiModelProperty("头像大小16x16")
    @JSONField(name = "16x16")
    private String url16x16;
    @ApiModelProperty("头像大小24x24")
    @JSONField(name = "24x24")
    private String url24x24;
    @ApiModelProperty("头像大小32x32")
    @JSONField(name = "32x32")
    private String url32x32;
    @ApiModelProperty("头像大小48x48")
    @JSONField(name = "48x48")
    private String url48x48;
    @ApiModelProperty("头像大小132x132")
    @JSONField(name = "132x132")
    private String url132x132;
    @ApiModelProperty("微信头像")
    @JSONField(name = "wx")
    private String urlWx;
    @ApiModelProperty("支付宝头像")
    @JSONField(name = "ali")
    private String urlAli;
    @ApiModelProperty("头像")
    @OneToOne(mappedBy = "avatar", fetch = FetchType.LAZY)
    @JSONField(serialize = false)
    private SysMember user;

    @ApiModelProperty("默认头像url")
    public String getUrl(){
        if (StringUtils.isNotEmpty(this.url132x132)){
            return this.url132x132;
        }else if(StringUtils.isNotEmpty(this.url48x48)){
            return this.url48x48;
        }else if(StringUtils.isNotEmpty(this.url32x32)){
            return this.url32x32;
        }else if(StringUtils.isNotEmpty(this.url24x24)){
            return this.url24x24;
        }else if(StringUtils.isNotEmpty(this.urlWx)){
            return this.urlWx;
        }else if(StringUtils.isNotEmpty(this.urlAli)){
            return this.urlAli;
        }else{
            return url16x16;
        }
    }
}
